package com.zhixiang.core.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.zhixiang.core.entity.TreeObj;

public class YearGridCrud {
    
    /*年份树表格yearGrid通用方法*/
    public static Map<String,String> getYearMap(){
        Map<String,String> yearMap = new LinkedHashMap<String,String>();
        int currentYear = Integer.parseInt(getCurrentYear());
        for(int i = 2014; i < currentYear + 3; i++){
            yearMap.put(String.valueOf(i), String.valueOf(i) + "年");
        }
        return yearMap;
    }
    
    public static String getCurrentYear(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        return sdf.format(new Date());
    }
    
    public static List<TreeObj> treeLoad()
    {
        List<TreeObj> children = new ArrayList<TreeObj>();
        Map<String, String> yearMap = getYearMap();
        for (Map.Entry<String, String> entry : yearMap.entrySet())
        {
            TreeObj obj = new TreeObj();
            obj.setId(entry.getKey());
            obj.setText(entry.getValue());
            obj.setParentId("All");
            //obj.setChecked(false);
            obj.setLeaf(true);
            children.add(obj);
        }
        
        List<TreeObj> root = new ArrayList<TreeObj>();
        TreeObj rootYear = new TreeObj();
        rootYear.setId("All");
        rootYear.setText("全部");
        rootYear.setParentId("");
        //rootYear.setChecked(false);
        rootYear.setLeaf(false);
        rootYear.setChildren(children);
        root.add(rootYear);
        List<TreeObj> treeList = new ArrayList<TreeObj>();
        treeList.addAll(root);
        return treeList;
    }
}
